import { get, post } from '@/request/index'
import request from '@/request/http'
import type { Ref } from 'vue'


/**
 * 获取智能体列表
 * @param loading 接口加载器
 * @returns 
 */
const getAgentList: (loading?: Ref<boolean>) => Promise<any> = (loading) => {
  return get('/chat/agent/getAgentList', undefined, loading)
}


/**
 * 通过智能体id获取历史记录
 * @param agentId 智能体ID
 * @param loading 接口加载器
 * @returns 
 */
const getChatList: (agentId?: string | number, loading?: Ref<boolean>) => Promise<any> = (agentId, loading) => {
  return get(`/chat/manage/getAll?agentId=${agentId}`, undefined, loading)
}


const deleteChat: (
  request: any,
  loading?: Ref<boolean>
) => Promise<any> = (request, loading) => {
  return post(`/chat/manage/delete?chatId=${request.chatId}`, undefined, undefined, loading)
}


const saveChat: (
  request: any,
  loading?: Ref<boolean>
) => Promise<any> = (request, loading) => {
  return post(`/chat/manage/save?agentId=${request.agentId}&chatName=${request.chatName}`, undefined, undefined, loading)
}

const pageQueryInfo: (
  chatId: any,
  request: any,
  loading?: Ref<boolean>
) => Promise<any> = (chatId, request, loading) => {
  return post(`/chat/manage/pageQueryInfo?chatId=${chatId}`, request, undefined, loading)
}

const queryExecute: (
  request: any,
  loading?: Ref<boolean>
) => Promise<any> = ( request, loading) => {
  return post(`/chat/query/execute`, request, undefined, loading)
}

const querySearch: (
  request: any,
  loading?: Ref<boolean>
) => Promise<any> = ( request, loading) => {
  return post(`/chat/query/search`, request, undefined, loading)
}


/** 获取主题域 */
const getDomainList: () => Promise<any> = () => {
  return get(`/semantic/domain/getDomainList`, undefined, )
}

/** 指标体系分页 */
const queryMetric: (
  request: any,
  loading?: Ref<boolean>
) => Promise<any> = ( request, loading) => {
  return post(`/semantic/metric/queryMetric`, request, undefined, loading)
}

/** 批量删除 */
const batchUpdateStatus: (
  request: any,
  loading?: Ref<boolean>
) => Promise<any> = ( request, loading) => {
  return post(`/semantic/metric/batchUpdateStatus`, request, undefined, loading)
}


/******************************* aibi ***********************/
const createQuestionId: (
  data: any,
) => Promise<any> = (data) => {
  return request({ url: '/chat/query/create', method: 'post', data })
}

const queryGetParse: (
  queryId: any,
) => Promise<any> = (queryId) => {
  return request({ url: `/chat/query/getParse/${queryId}`, method: 'get' })
}


export default {
    getAgentList,
    getChatList,
    deleteChat,
    saveChat,
    pageQueryInfo,
    queryExecute,
    createQuestionId,
    queryGetParse,
    querySearch,
    getDomainList,
    queryMetric,
    batchUpdateStatus,
}
